package com.zhoug.libapp.test;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.zhoug.libapp.R;
import com.zhoug.widget.customview.SignView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SignViewActivity extends AppCompatActivity {

    @BindView(R.id.signView)
    SignView signView;
    @BindView(R.id.btn_clear)
    Button btnClear;
    @BindView(R.id.btn_confirm)
    Button btnConfirm;
    @BindView(R.id.imageView)
    ImageView imageView;
    @BindView(R.id.testView)
    TestView testView;
    @BindView(R.id.btn3)
    Button btn3;
    @BindView(R.id.imageView2)
    ImageView imageView2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_view);
        ButterKnife.bind(this);

      /*  signView.setBackgroundColor(Color.parseColor("#0000ff"));
        signView.setColor(Color.RED);
        signView.setPaintWidth(10);*/
    }

    private void clear() {
        signView.clear();
    }

    private void confirm() {
        Bitmap bitmap = signView.getBitmap();
        setImageView(bitmap);
    }

    private void clearBank() {
        setImageView(signView.getClearBlankBitmap(10));
        Toast.makeText(this, "清除边界", Toast.LENGTH_SHORT).show();
    }

    private void setImageView(Bitmap bitmap) {
        if (bitmap != null) {
            imageView.setImageBitmap(bitmap);
        } else {
            Toast.makeText(this, "bitmap=null", Toast.LENGTH_SHORT).show();
        }
    }

    @OnClick({R.id.btn_clear, R.id.btn_confirm, R.id.btn_clearBank,R.id.btn3})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_clear:
                clear();
                break;
            case R.id.btn_confirm:
                confirm();
                break;
            case R.id.btn_clearBank:
                clearBank();
                break;
            case R.id.btn3:
                imageView2.setImageBitmap(testView.getBitmap());

                break;
        }
    }


}
